﻿
using Microsoft.SharePoint.Client;
using System.Net;
using System.Security;
namespace SPIE.Console
{
    public class UserCredentials
    {
        public string Name { get; set; }
        public string Password { get; set; }
        public CredentialsType CredentialsSource { get; set; }

        public UserCredentials(string name, string password, CredentialsType type)
        {
            Name = name;
            Password = password;
            CredentialsSource = type;
        }

        public ICredentials GetCredentials()
        {
            switch (CredentialsSource)
            {

                case CredentialsType.SharePointOnline:
                    SecureString securePassword = new SecureString();
                    foreach (char c in Password.ToCharArray()) securePassword.AppendChar(c);
                    SharePointOnlineCredentials cred = new SharePointOnlineCredentials(Name, securePassword);
                    return cred;
                case CredentialsType.Unknown:
                default:
                    return null;
            }
        }
    }
}
